<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>用户登录-潮聚</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" th:href="@{css/mui.min.css}"/>
		<link rel="stylesheet" th:href="@{css/common.css}"/>
		<link rel="stylesheet" th:href="@{css/icons-extra.css}"/>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">登录</h1>
		</header>
		<div class="cj-line-20"></div>
		<div class="mui-content">
			<form  method="post" id='login-form' class="mui-input-group">
				<div class="mui-input-row">
					<label>邮箱</label>
					<input name="email"  type="text" class="mui-input-clear mui-input" placeholder="请输入邮箱">
				</div>
				<div class="mui-input-row mui-password">
					<label>密码</label>
					<input name="password"  type="password" class="mui-input-clear mui-input" placeholder="请输入密码">
				</div>
			</form>
			<div class="cj-line-10"></div>
			<form class="mui-input-group">
				<ul class="mui-table-view mui-table-view-chevron">
					<li class="mui-table-view-cell">
						记住密码
						<div id="autoLogin" class="mui-switch">
							<div class="mui-switch-handle"></div>
						</div>
					</li>
				</ul>
			</form>
			<div class="cj-line-10"></div>
			<div class="mui-content-padded">
				<button id='login' data-loading-text="登陆中" class="mui-btn mui-btn-block mui-btn-primary cj-btn">登录</button>
				<div class="cj-line-10"></div>
				<div class="link-area mui-text-center">
					<a id='reg' href="/register">注册账号</a> <span class="spliter">|</span>
					<a id='forgetPassword'>忘记密码</a>
				</div>
			</div>
			<div class="mui-content-padded oauth-area">
			</div>
		</div>
	<div th:include="common/footer :: nav"></div>
	<script src="js/mui.min.js"></script>
    <script src="js/jquery.min.js"></script>
    <script src="js/common.js"></script>
    <script>
    	$("#login").click(function(){
			var email = $("input[name='email']").val();
			var emailRegx = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
			if(!emailRegx.test(email)){
				mui.toast("请输入正确的邮箱");
				return;
			}
			
			var password = $("input[name='password']").val();
			if(password==null||password==""){
				mui.toast("请输入密码"+password);
				return;
			}
			var loginData = $("form").serialize();
			$.ajax({
					url:"/login" ,
					data:loginData,
					type:'post',
					dataType:'json',
					beforeSend:function(){
						mui("#login").button('loading');
					},
					success:function(response){
						if( response.code==500){
							mui.toast(response.msg);
						}else{
							
							if(typeof(response.result)=="undefined"){
									location.href = "/user"
							}else{
									location.href= response.result;
							}
						}
						mui("#login").button('reset');
					}
				});
		});
    </script>
	</body>
</html>